package org.lease.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lease.common.result.Result;
import org.lease.model.entity.CityInfo;
import org.lease.model.entity.DistrictInfo;
import org.lease.model.entity.ProvinceInfo;
import org.lease.service.CityInfoService;
import org.lease.service.DistrictInfoService;
import org.lease.service.ProvinceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "地区信息")
@RestController
@RequestMapping("/app/region")
public class RegionController {
    @Autowired
    private ProvinceInfoService provinceInfoService;
    @Autowired
    private CityInfoService cityInfoService;
    @Autowired
    private DistrictInfoService districtInfoService;

    @Operation(summary = "查询所有省份")
    @GetMapping("/province/list")
    public Result<List<ProvinceInfo>> getProvinceList() {
        List<ProvinceInfo> list = provinceInfoService.list();
        return Result.success(list);
    }

    @Operation(summary = "根据省份 ID 查询城市")
    @GetMapping("/city/listByProvinceId")
    public Result<List<CityInfo>> getCityList(Long id) {
        List<CityInfo> list = cityInfoService.listByProvinceId(id);
        return Result.success(list);
    }

    @Operation(summary = "根据城市 ID 查询地区")
    @GetMapping("/district/listByCityId")
    public Result<List<DistrictInfo>> getDistrictList(Long id) {
        List<DistrictInfo> list = districtInfoService.listByCityId(id);
        return Result.success(list);
    }
}
